#ifndef __RECEIVER_H
#define __RECEIVER_H

#include<functional>
#include<iostream>
#include<stdlib.h>
#include<string.h>
#include<sys/socket.h>
#include<sys/types.h>
#include<unistd.h>
#include<arpa/inet.h>
#include<netinet/in.h>
#include<thread>
#include<chrono>
#include<pthread.h>


#include"udp_socket.h"
#include"timer.h"
#include"color.h"
#include"clock.h"


using namespace std;

#define BUFF_LENGTH 1024





/***************************************
			Class Receiver
***************************************/
class Receiver
{
public:
	Receiver();
	~Receiver();


	/*
	server
		Receiver udp_cs;
		udp_cs.run_receiver();
	*/
	void run_receiver();
	void preset_receiver();
	void start_receiver();

	void stop_receiver();


//private:
	
	Clock m_clock;
	char buff[BUFF_LENGTH];
	char data[BUFF_LENGTH];


	bool receiver_running ;



	int server_fd;
	struct sockaddr_in ser_addr;

	//server
	int server_port;

};

/***************************************
			Class ReceiverController
***************************************/
class ReceiverController
{
public:
	ReceiverController(){};
	~ReceiverController(){};
	static void udpCs_install( Receiver *udpCs );
	static void udpCs_stop_receiver();
	
//private:
	static Receiver *udpCs_ptr;
};

//Receiver *ReceiverController::udpCs_ptr = NULL;

/***************************************
			Class ReceiverThread
***************************************/
class ReceiverThread
{
public:
	ReceiverThread();
	~ReceiverThread();
	void run_independent_receiver();
	void wait_for_receiver();

//private:
	Receiver udpCs;
	thread *t_receiver;
};


#endif
